directive.directive('echarts',[function() {
    var instanceCache=[];

    return {
        restrict:'E',
        replace:true,
        template:'<div></div>',
        link:function($scope,$element,$attrs){
            var optionVar=$element.attr('options');

            $scope.$watch($attrs.options,function(options) {
                if(objectUtil.isNull(options)) {
                    return;
                }

                var inited=$element.attr('inited');
                if(objectUtil.isNull(inited)) {
                    $element.attr('inited',true);

                    var charts=echarts.init($element[0]);
                    charts.setOption(options);

                    instanceCache[optionVar]=charts;
                }
                else {
                    instanceCache[optionVar].setOption(options);
                }
            });
        }
    };
}]);